import {defineStore} from "pinia";
import {SurfaceSettingModel} from "@/store/model/SurfaceSettingModel";
import {post, Response} from "@/api/http";
import {getConsts, saveSurfaceSetting} from "@/api/url";
import {obj2Map} from "@/utils";
import {renderIcon} from "@/hooks/form";
import {Book} from "@vicons/ionicons5";

export class ConstsModel{
    constructor(stateMap: Map<number, string>, panelStateMap: Map<number, string>, taskTypeMap: Map<number, string>, taskLogTypeMap: Map<number, string>, dayUnitMap: Map<number, string>) {
        this.stateMap = stateMap;
        this.panelStateMap = panelStateMap;
        this.taskTypeMap = taskTypeMap;
        this.taskLogTypeMap = taskLogTypeMap;
        this.dayUnitMap = dayUnitMap;
    }

    stateMap:Map<number, string>;
    panelStateMap:Map<number, string>;
    taskTypeMap:Map<number, string>;
    taskLogTypeMap:Map<number, string>;
    dayUnitMap:Map<number, string>;

    static getNewConstsModel(){
        return new ConstsModel(new Map(),new Map(),new Map(),new Map(),new Map())
    }
}

export const UseConstsStore = defineStore("consts", {
    state() {
        const consts = ConstsModel.getNewConstsModel();
        return {
            consts: consts,
        };
    },
    actions: {
        getLabelValue:function (map:Map<number,string>){
            const stateMap = obj2Map(map)
            const satgeMenuOptions = [];
            for (const stateMapKey of stateMap.keys()) {
                satgeMenuOptions.push({
                    label:stateMap.get(stateMapKey),
                    value:stateMapKey,
                })
            }
            return satgeMenuOptions;
        },
        getDayUnitMap:function() {
            const stateMap = obj2Map(this.getConsts().dayUnitMap)
            const satgeMenuOptions = [];
            for (const stateMapKey of stateMap.keys()) {
                satgeMenuOptions.push({
                    label:stateMap.get(stateMapKey),
                    value:stateMapKey,
                })
            }
            return satgeMenuOptions;
        },
        getStateList: function (){
            const stateMap = obj2Map(this.getConsts().stateMap)
            const satgeMenuOptions = [];
            for (const stateMapKey of stateMap.keys()) {
                satgeMenuOptions.push({
                    label:stateMap.get(stateMapKey),
                    key:stateMapKey,
                })
            }
            return satgeMenuOptions;
        },
        getConsts:function (){
            return this.consts;
        },
        getConstsFromBack: async function (token:any){
            try {
                const {data}: Response = await post({
                    url: getConsts,
                    token:token
                });
                this.consts =  data.data as ConstsModel;
            }catch(e) {
                console.log(e)
                // message.error((e as Error).message)
            }
        }
    },
    getters: {},
});